/* [n_test]
 *********************
 * Things to remember:
 *
 * - detail is threadsafe, use caution, all changes will be seen by all threads; recommend: only use to .get data never .set
 * - global variables are global to all threads, use load & unload to initialize & free up memory
 * - use global isInit to initialize global variables requiring detail to be setup
 * - when using global isInit, the code must be mutex protected so all threads do not run the init, just one
 * - inter-thread coordination can be coordinated via the provided mutex
 */
#include <process.h>
#include <stdio.h>

#define DLL_EXPORT
#include "start.h"
#include "Exec.h"

#include <iostream>
using namespace std;

#ifdef _WIN32
#ifdef _DEBUG
   #include <crtdbg.h>
   #undef THIS_FILE
   static char THIS_FILE[] = __FILE__;
   #define new       new( _NORMAL_BLOCK, __FILE__, __LINE__)
   #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif	/*__cplusplus*/


// default global variables within dll
ParamManager *supported = NULL;
// module-specific global variables within dll
//bool isInit = false;
//Database *db = NULL;


// called after the module is loaded, useful to load global variables; Returns supported actions as a ParamManager*
DECLDIR ParamManager* load(void) {
	supported = new ParamManager();
	supported->setOverwrite(false);
	supported->set("action", "test");

	return supported;
}


// called just before the module is unloaded, useful to unload global variables
DECLDIR void unload(void) {
	if(supported) {
		delete supported;
	}
}


DECLDIR void start(HANDLE mutex, ParamManager &detail, char *index) {
//	char *tmp = BN_bn2dec(todo->id);
//	printf("id: '%s'\r\n", tmp);
//	OPENSSL_free(tmp);

//	char cmd[DEFAULT_BUFLEN];
//	sprintf(cmd, "c:\\cygwin\\bin\\ls.exe c:\\windows\\temp");
//	Exec proc(cmd);

#ifdef _DEBUG
//	printf("test thread, index = %s\n", index);
#endif // _DEBUG

//	Sleep(1000);

	// free up mysql thread-specific memory
//	mysql_thread_end();
}


#ifdef __cplusplus
}
#endif	/*__cplusplus */